#include "table.h"
#include "transaction.h"
#include <stdio.h>
#include <stdlib.h>

int main() {

  struct table *T = table_new(string_new("user"));
  table_add_col_def(T, string_new("id"), TYPE_INT, 10);
  table_add_col_def(T, string_new("name"), TYPE_CHAR, 20);
  table_add_col_def(T, string_new("age"), TYPE_INT, 3);
  table_add_col_def(T, string_new("sex"), TYPE_INT, 3);
  table_add_col_def(T, string_new("group_no"), TYPE_INT, 4);

  transaction_sys_init();
  struct transaction *TX = transaction_new();

  struct condition **conditions = malloc(sizeof(struct string *) * 3);
  conditions[0] = condition_new(string_new("group_no"), EQUALS, string_new("2"));
  conditions[1] = condition_new(string_new("age"), EQUALS, string_new("29"));
  conditions[2] = condition_new(string_new("sex"), EQUALS, string_new("男"));
  struct string *result = tx_table_select(T,TX, conditions, 3);

  printf("%s\n", result->chs);

  string_free(result);
  condition_free(conditions[0]);
  condition_free(conditions[1]);
  condition_free(conditions[2]);
  free(conditions);

  table_free(T);
  return 0;
}